package com.longyiqun.cm.mapper;

import com.longyiqun.cm.domain.BaseServerEntity;
import com.longyiqun.cm.domain.BuildRecordEntity;
import com.longyiqun.cm.domain.ComboBox;
import com.longyiqun.cm.domain.LoginInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface ServerMapper {
    @Select("${sql}")
    List<Map<String,String>> findBaseServer(@Param("sql") String sql);

    @Select("SELECT * from tbServerInfo where serverId = #{serverId}")
    BaseServerEntity findOneById(@Param("serverId") String serverId);


    @Select("SELECT * from tbBuildRecord where vServerName like #{vServerName} and eAudit like  #{eAudit} and vLeader like #{vLeader} and eStatus = 1 order by dtCreateTime desc")
    List<BuildRecordEntity> findbuildRecord(@Param("vServerName") String vServerName, @Param("eAudit") String eAudit, @Param("vLeader") String vLeader);
    @Select("SELECT * from tbBuildRecord where buildId = #{buildId}")
    BuildRecordEntity findbuildApplyByID(@Param("buildId")String buildId);
    @Update("UPDATE tbBuildRecord set eAudit = 2 where buildId = #{buildId}")
    int AuditBuildApply(@Param("buildId")String buildId);
    @Insert("INSERT into tbBuildRecord (vServerName,vBranch,vLeader,vDev,serverType,vVersion) VALUE(#{vServerName},#{vBranch},#{vLeader},#{vDev},#{serverType},#{vVersion})")
    int addBuildService(BuildRecordEntity buildRecordEntity);

    @Select("SELECT * from tbBuildRecord where vServerName = #{vServerName}")
    List<BuildRecordEntity> findRecordByServerName(@Param("vServerName")String vServerName);

    @Update("UPDATE tbServerInfo set vServerName = #{vServerName},vLeader = #{vLeader},vGitUrl=#{vGitUrl},vLanguage=#{vLanguage},vProduct=#{vProduct},vDeploy=#{vDeploy},vSystem=#{vSystem} where serverId=#{serverId}")
    int UpdateBaseServer(BaseServerEntity baseServerEntity);



    @Select("SELECT * from tbUserInfo where username = #{username}")
    LoginInfo GetUserInfoMp(@Param("username")String username);
    @Select("SELECT Count(*) as count from tbUserInfo where username = #{username}")
    int GetUserInfoCount(@Param("username")String username);

    //系统配置表
    @Select("Select vSystem from tbSystemConf")
    List<ComboBox>ComboBox_System();

    //部署配置表
    @Select("Select * from tbDeployConf")
    List<ComboBox>ComboBox_Deploy();

    @Select("Select deployID from tbDeployConf where vDeployType = #{vDeployType} and vDeployUrl=#{vDeployUrl} and eStatus = 1" )
    String getDeployFromConf(@Param("vDeployType")String vDeployType,@Param("vDeployUrl")String vDeployUrl);

    @Select("Select vProduct from tbProductConf")
    List<ComboBox>ComboBox_Product();

    @Select("Select vServer from tbServerTypeConf")
    List<ComboBox>ComboBox_Server();

    @Select("Select vLanguage from tbLanguageConf group by vLanguage")
    List<ComboBox>ComboBox_vLanguage();
    @Select("Select languageID from tbLanguageConf where vLanguage=#{vLanguage} and vCompile = #{vCompile} and eStatus =1 limit 1")
    String getLanguageFromConf(@Param("vLanguage")String vLanguage,@Param("vCompile")String vCompile);

    @Insert("INSERT into tbServerInfo (vServerName,vSystem,vServerType,vGitUrl,eLanguage,eDeploy,vLeader,eStatus) VALUE(#{vServerName},#{vSystem},#{vServerType},#{vGitUrl},#{eLanguage},#{eDeploy},#{vLeader},#{eStatus})")
    int addBaseService(BaseServerEntity baseServerEntity);

    @Insert("insert into tbLanguageConf (vLanguage,vCompile) value (#{vLanguage} , #{vCompile})")
    int addLanguageConf(@Param("vLanguage")String vLanguage,@Param("vCompile")String vCompile);

    @Select("select * from tbServerInfo where vServerName = #{vServerName} and eStatus= 1")
    List<BaseServerEntity> CheckServer(@Param("vServerName")String vServerName);

    @Update("update tbServerInfo set eStatus = -1 where serverId = #{serverId}")
    int  deleteServer(@Param("serverId")String serverId);

    @Select("${sql} limit 1")
    Map<String,String> Select_Sql_Only(@Param("sql")String sql);
}
